/*!
* URL转跨域代理[用于AJAX代理]
* @param string u, URL链接
* @return string, 跨域请求代理地址
*/
$.fn.urlCross = function(s){
	return $.muicfg.crossProxy + $.fn.urlEnc(u);	
};
/*!
* URL转URLDECODE
* @param string u, URL链接
* @return string, deCode后的链接
*/
$.fn.urlDec = function(u){
	u = u.replace(/%3A/ig, ':');
	u = u.replace(/%2F/ig, '/');
	u = u.replace(/%3F/ig, '?');
	u = u.replace(/%3D/ig, '=');
	u = u.replace(/%23/g, '#');
	u = u.replace(/%26/g, '&');
	u = u.replace(/\+/g, ' ');
	return u;
};
/*!
* URL转URLENCODE
* @param string u, URL链接
* @return string, enCode后的链接
*/
$.fn.urlEnc = function(u){
	u = u.replace(/:/g, '%3A');
	u = u.replace(/\//g, '%2F');
	u = u.replace(/\?/g, '%3F');
	u = u.replace(/=/g, '%3D');
	u = u.replace(/#/g, '%23');
	u = u.replace(/&/g, '%26');
	u = u.replace(/ /g, '+');
	return u;
};
/*!
* URL转URLOBJECT
* @param string u, URL链接
* @param boolean nocross, 不检查跨域
* @example http://www.example.com/directory/filename.php?a=b&c=d#efg
*          http://user:port@www.example.com/directory/filename.php?a=b&c=d#efg
* @return object s, URL分解属性
*                string protocol, 协议(http|https)
*                string username, 验证用户名
*                string password, 验证密码
*                string host, 主机名
*                string port, 端口号
*                string directory, 请求目录(如: /directory/)
*                string filename, 请求文件(如: filename.php)
*                string pathname, 请求路径(如: /directory/filename.php)
*                string search, 请求参数(如: ?a=b&c=d)
*                string hash, 请求哈希(如: #efg)
*                string cross, 跨域后代理URL完整格式
*/
$.fn.urlObj = function(u, nocross){
	u = u.toString().replace(/&amp;/ig, '&');
	/**
	* @var string e, 正则匹配规则
	* @var array m, 匹配结果
	* @var object s, 返回格式化
	*/
	var e = /^\s*(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/, 
		m = e.exec(u) || [], 
		s = {
			url : '', 
			protocol : '',
			username : '',
			password : '',
			host : '',
			port : '',
			directory : '',
			filename : '',
			pathname : '',
			search : '',
			hash : '', 
			cross : false
		};
	/*!
	* 按数组匹配分配返回对象
	*/
	$(m).each(function(i, v) {
		if (v) {
			switch (i) {
				case 4 : s.protocol = v; break;
				case 8 : s.username = v; break;
				case 9 : s.password = v; break;
				case 11 : s.host = v; break;
				case 12 : s.port = v; break;
				case 13 : s.pathname = v; break;
				case 14 : s.directory = v; break;
				case 15 : s.filename = v; break;
				case 16 : s.search = v; break;
				case 17 : s.hash = v; break;
			}
		}
	});
	/*!
	* 不检查跨域
	*/
	if (nocross === true){
		return s;
	}
	/*!
	* 当前URL值
	*/
	var c = $.fn.urlObj(window.location.href, true);
	/*!
	* 不带协议
	*/
	if (!u.match(/^([a-z0-9]+):\/\//i)){
		s.protocol = s.protocol || c.protocol;
		s.username = s.username || c.username;
		s.password = s.password || c.password;
		s.host = s.host || c.host;
		s.port = s.port || c.port;
		/*!
		* 不带路径
		*/
		if (!u.match(/^\//)){
			s.directory = (c.directory || '/') + s.directory; if (u.match(/^#/)){
			s.filename = c.filename; }
			s.pathname = s.directory+s.filename;
		}
	}
	/*!
	* 协议
	*/
	if (s.protocol){
		s.url += s.protocol+'//';
	}
	/*!
	* 验证
	*/
	if (s.username){
		s.url += s.username; if (s.password){
		s.url += ':'+s.password; }
		s.url += '@';
	}
	/*!
	* 主机
	*/
	s.url += s.host; if (s.port){
	s.url += ':'+s.port; }
	/*!
	* 路径/参数/哈希
	*/
	s.url += s.pathname;
	s.url += s.search;
	s.url += s.hash;
	/*!
	* 如果已经跨域
	*/
	if (s.protocol != c.protocol || s.host != c.host || s.port != c.port){
		s.cross = true;
	} return s;
};
/*!
* URL唯一吗
* @param string u, URL地址
*/
$.fn.urlUid = function(u){
	var o = $.fn.urlObj(u), 
		l = 0, 
		s = 0; 
	$(o.url.split('')).each(function(k, v){
		l++; s += v.charCodeAt(0);
	}); return 'l'+l+'s'+s;
};